<template>
    <div id="school-det">
        <el-breadcrumb separator="/" class="common-bread">
            <el-breadcrumb-item :to="{ path: '/school' }">学校管理</el-breadcrumb-item>
            <el-breadcrumb-item>学校详情</el-breadcrumb-item>
        </el-breadcrumb>

        <div class="form mt10 contentBox">
            <div class="list_head">
                <span class="head_name">学校信息</span>
                <el-button type="primary" @click="$router.push('/school')" class="fr ml10">返回</el-button>
            </div>
            <el-form label-width="120px" :model="form" ref="form" disabled>
                <el-form-item label="学校编号：" prop="schoolCode">
                    <el-input v-model="form.schoolCode"></el-input>
                </el-form-item>
                <el-form-item label="学校名称：" prop="name">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="省市：" prop="cityId" required>
                    <el-select v-model="form.cityId">
                        <el-option :label='item.areaName' :value='item.areaId' v-for="item in cities" :key="item.areaId"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="区县：" prop="zoneId" required>
                    <el-select v-model="form.zoneId">
                        <el-option :label='item.areaName' :value='item.areaId' v-for="item in zones" :key="item.areaId"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="类型：" prop="schoolType">
                    <el-checkbox-group v-model="form.schoolType">
                        <el-checkbox label="高中"></el-checkbox>
                        <el-checkbox label="初中"></el-checkbox>
                        <el-checkbox label="小学"></el-checkbox>
                    </el-checkbox-group>
                </el-form-item>
                <el-form-item label="标签：" prop="tags">
                    <div class="tagsContain">
                        <span class="tag" v-for="(item,index) in tags">{{item}}</span>
                    </div>
                </el-form-item>

            </el-form>
        </div>
    </div>
</template>

<script>
    import { mapState, mapActions } from "vuex";

    export default {
        data() {
            return {
                id: "",
                operationText: "添加",
                tags: ["重点小学"],
                tag: '',
                form: {
                    schoolCode: "",
                    name: "",
                    cityId: null,
                    zoneId: null,
                    schoolType: []
                },
                cities: [],
                zones: []
            }
        },
        computed: mapState({ user: state => state.user }),
        mounted() {
            this.id = this.$util.getUrlParam("id");
            this.getDetail();
            this.$util.setStore("schSelect", "1");
        },
        methods: {
            //获取学校详情
            getDetail() {
                this.$axios.get("/adminapi/v1/tools/schools/info?schoolId=" + this.id).then(response => {
                    if (response.data.error == 10000) {
                        let info = response.data.data;
                        this.tags = info.tags ? info.tags.split("-") : [];
                        let schoolType = [];
                        if (info.haveHigh) {
                            schoolType.push("高中");
                        }
                        if (info.havePrimary) {
                            schoolType.push("小学");
                        }
                        if (info.haveMiddle) {
                            schoolType.push("初中");
                        }
                        this.$util.getCityAndZoneById(info.areaId).then(area => {
                            this.cities = [area.city];
                            this.zones = [area.zone];
                            this.form = {
                                schoolCode: info.schoolCode,
                                name: info.name,
                                schoolType: schoolType,
                                cityId: area.city.areaId,
                                zoneId: area.zone.areaId
                            };
                        })

                    }
                })
            }
        }
    }
</script>
<style>
    .tagsContain {
        width: 700px;
        height: 135px;
        /* margin-left: 120px; */
        margin-bottom: 30px;
        border: solid 1px gray;
        box-sizing: border-box;
        overflow-y: scroll;
    }

    span.tag {
        display: block;
        text-align: center;
        float: left;
        line-height: 1.5;
        padding: 5px 15px;
        border: solid 1px #999;
        border-radius: 5px;
        margin: 10px;
        box-sizing: border-box;
        font-size: 12px;
        position: relative;
        cursor: pointer;
    }

    #school-det .el-select {
        width: 300px;
    }

    #school-det .el-select>.el-input,
    #school-det .select-head>.el-input {
        width: 300px;
    }
</style>